package cn.itsource.org.service.impl;

import cn.itsource.org.domain.Employee;
import cn.itsource.org.domain.Product;
import cn.itsource.org.mapper.ProductMapper;
import cn.itsource.org.query.ProductQuery;
import cn.itsource.org.service.ProductService;
import cn.itsource.utli.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Product> queryAll() {
        return productMapper.queryAll();
    }

    /**
     * 删除
     * @param id
     */
    @Override
    @Transactional
    public void delete(Long id) {
        productMapper.delete(id);
    }

    /**
     * 新增
     * @param Product
     */
    @Override
    @Transactional
    public void save(Product Product) {
        productMapper.save(Product);
    }

    /**
     * 修改
     * @param Product
     */
    @Override
    @Transactional
    public void update(Product Product) {
        productMapper.update(Product);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Product queryById(Long id) {
        return productMapper.queryById(id);
    }

    /**
     * 分页
     * @param query
     * @return
     */
    @Override
    public PageInfo<Product> queryPage(ProductQuery query) {
        Long count = productMapper.count(query);
        List<Product> list = productMapper.queryDate(query);
        return new PageInfo<>(count,list);
    }

}
